Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
'Imports DotNetNuke.Installer
Imports ICSharpCode.SharpZipLib.Zip
Imports System.IO
Imports DotNetNuke
Imports System.Net

Namespace NVPortal.Modules.NVNews

    Public MustInherit Class Edit
        Inherits Entities.Modules.PortalModuleBase
        Dim tin As Integer

#Region "Event Handlers"
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not IsPostBack Then
                Try
                    BindddlCategories()
                    BindNewsRelated()
                    BindNguonTin()
                    BindddlCategories2()
                    binddrgDataViewerR()

                    '<Edit news>
                    If Request.Item("tin") <> "" Then
                        'Me.tdTinlienquan.Visible = True
                        Dim tin As String
                        tin = Request.Item("tin")
                        ' Hien thi tin nay
                        Dim ctlNews As New NV_NewsController
                        Dim objNews As NV_NewsInfo
                        objNews = ctlNews.GetByID(Request.Item("tin"))
                        Me.txtTitle.Text = objNews.Title
                        Me.txtSummary.Text = objNews.Summary
                        Me.TextEditor1.Text = objNews.Content
                        Me.txtLinkNguon.Text = objNews.LinkNguon
                        Me.TextEditor2.Text = objNews.Exsummary
                        Me.chkHotCat.Checked = objNews.Hotcat
                        Me.chkHotSite.Checked = objNews.Hotsite
                        Me.chkNotes.Checked = objNews.Notes
                        Me.chkBL.Checked = objNews.BinhLuan
                        If Not objNews.ImagePath Is Nothing Then
                            If objNews.ImagePath.ToString.Contains("http://") Then
                                Me.imgNews.Visible = True
                                Me.imgNews.ImageUrl = objNews.ImagePath
                                Me.txtLinkImage.Text = objNews.ImagePath
                            Else
                                Me.imgNews.Visible = True
                                Me.imgNews.ImageUrl = objNews.ImagePath
                            End If
                        End If
                        If Not objNews.ImagePathHOT Is Nothing Then
                            If objNews.ImagePathHOT.ToString.Contains("http://") Then
                                Me.imgNews.Visible = False
                                Me.imgNewsHOT.ImageUrl = objNews.ImagePathHOT
                                Me.txtLinkImageHOT.Text = objNews.ImagePathHOT
                            Else
                                Me.imgNewsHOT.Visible = True
                                Me.imgNewsHOT.ImageUrl = objNews.ImagePathHOT
                            End If
                        End If
                        Me.ddlCategory.SelectedValue = objNews.CategoryId
                        Me.ddlNguonTin.SelectedValue = objNews.Nguon
                        If UserInfo.IsInRole("DuyetBai") Then
                            Me.lbtGuiluon.Visible = True
                        Else
                            Me.lbtGuiluon.Visible = False
                        End If

                    Else
                        Me.tdTinlienquan.Visible = False
                        Me.lbtGuiluon.Visible = False
                    End If
                    
                    '</Edit news>
                Catch ex As Exception
                    ProcessModuleLoadException(Me, ex)
                End Try
            End If
        End Sub
        Private Sub lbtCancelBottom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtCancelBottom.Click
            Try
                Response.Redirect(NavigateURL(), True)
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
        Private Sub lbtUpdateTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtUpdateTop.Click
            If addnews() Then
                'clearcontroldata()
                'addnewsvideo("idtintuc")
            End If
        End Sub
        Private Function addnews() As Boolean
            Try
                If Request.Item("tin") <> "" Then
                    Dim tin As String
                    tin = Request.Item("tin")
                    'update news

                    Dim stitle As String
                    Dim ssummary As String
                    Dim scontent As String
                    Dim spicture As String
                    Dim spictureHOT As String
                    Dim iCategory As String
                    Dim iHotsite As Integer
                    Dim iNotes As Integer
                    Dim iHotCat As Integer
                    Dim sExSummary As String
                    Dim sConTentImg As String
                    Dim iBL As Integer
                    Dim inguon As Integer
                    ' Insert

                    stitle = Me.txtTitle.Text
                    ssummary = Me.txtSummary.Text
                    sExSummary = TextEditor2.Text
                    scontent = TextEditor1.Text
                    sConTentImg = txtLinkNguon.Text
                    If txtLinkImage.Text <> "" Then
                        spicture = txtLinkImage.Text
                    Else
                        If Me.imgNews.ImageUrl <> "" Then
                            spicture = Path.GetDirectoryName(imgNews.ImageUrl) & "/" & Path.GetFileName(imgNews.ImageUrl)
                            spicture = spicture.Replace("\Portals\0\News\", "")
                            spicture = spicture.Replace("\", "/")
                        Else
                            spicture = ""
                        End If
                    End If

                    If txtLinkImageHOT.Text <> "" Then
                        spictureHOT = txtLinkImageHOT.Text
                    Else
                        If Me.imgNewsHOT.ImageUrl <> "" Then
                            spictureHOT = Path.GetDirectoryName(imgNewsHOT.ImageUrl) & "/" & Path.GetFileName(imgNewsHOT.ImageUrl)
                            spictureHOT = spictureHOT.Replace("\Portals\0\News\HOT\", "")
                            spictureHOT = spictureHOT.Replace("\", "/")
                        Else
                            spictureHOT = ""
                        End If
                    End If
                    iCategory = Me.ddlCategory.SelectedItem.Value
                    iHotCat = CInt(IIf(Me.chkHotCat.Checked(), 1, 0))
                    iHotsite = CInt(IIf(Me.chkHotSite.Checked(), 1, 0))
                    iNotes = CInt(IIf(Me.chkNotes.Checked(), 1, 0))
                    iBL = CInt(IIf(Me.chkBL.Checked(), 1, 0))
                    inguon = CInt(Me.ddlNguonTin.SelectedItem.Value)
                    DataProvider.Instance.NV_News_update(tin, iCategory, stitle, spicture, ssummary, scontent, 1, iHotCat, iHotsite, iNotes, PortalId, sExSummary, sConTentImg, spictureHOT, iBL, inguon)
                    Response.Redirect(NavigateURL(), True)
                Else
                    Dim iTin As String
                    Dim stitle As String
                    Dim ssummary As String
                    Dim scontent As String
                    Dim spicture As String
                    Dim spictureHOT As String
                    Dim iCategory As String
                    Dim iHotsite As Integer
                    Dim iNotes As Integer
                    Dim iHotCat As Integer
                    Dim sExSummary As String
                    Dim sConTentImg As String
                    Dim iBL As Integer
                    Dim inguon As Integer
                    ' Insert
                    iTin = Date.Now.ToString("yyyMMddHHmmss")
                    stitle = Me.txtTitle.Text
                    ssummary = Me.txtSummary.Text
                    sExSummary = TextEditor2.Text
                    scontent = TextEditor1.Text
                    sConTentImg = txtLinkNguon.Text

                    If txtLinkImage.Text <> "" Then
                        spicture = txtLinkImage.Text
                    Else
                        If Me.imgNews.ImageUrl <> "" Then
                            spicture = Path.GetDirectoryName(imgNews.ImageUrl) & "/" & Path.GetFileName(imgNews.ImageUrl)
                            spicture = spicture.Replace("\Portals\0\News\", "")
                            spicture = spicture.Replace("\", "/")
                        Else
                            spicture = ""
                        End If
                    End If

                    If txtLinkImageHOT.Text <> "" Then
                        spictureHOT = txtLinkImageHOT.Text
                    Else
                        If Me.imgNewsHOT.ImageUrl <> "" Then
                            spictureHOT = Path.GetDirectoryName(imgNewsHOT.ImageUrl) & "/" & Path.GetFileName(imgNewsHOT.ImageUrl)
                            spictureHOT = spictureHOT.Replace("\Portals\0\News\HOT\", "")
                            spictureHOT = spictureHOT.Replace("\", "/")
                        Else
                            spictureHOT = ""
                        End If
                    End If

                    iCategory = Me.ddlCategory.SelectedItem.Value
                    iHotCat = CInt(IIf(Me.chkHotCat.Checked(), 1, 0))
                    iHotsite = CInt(IIf(Me.chkHotSite.Checked(), 1, 0))
                    iNotes = CInt(IIf(Me.chkNotes.Checked(), 1, 0))
                    iBL = CInt(IIf(Me.chkBL.Checked(), 1, 0))
                    inguon = CInt(Me.ddlNguonTin.SelectedItem.Value)
                    'isactive = CInt(IIf(Me.chkHotSite.Checked(), 1, 0))
                    DataProvider.Instance.NV_News_Add(iTin, iCategory, stitle, spicture, ssummary, scontent, 1, iHotCat, iHotsite, iNotes, PortalId, UserId, sExSummary, sConTentImg, spictureHOT, iBL, inguon)
                    Me.lbResult.Text = "Cập nhật tin thành công"
                    Response.Redirect(NavigateURL(), True)
                End If
                Return True
            Catch ex As Exception
                Me.lbResult.Text = "Lỗi cập nhật tin"
                ProcessModuleLoadException(Me, ex)
                Return False
            End Try
        End Function
        Private Sub lbtUpdateBottom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtUpdateBottom.Click
            If addnews() Then
                clearcontroldata()
                ' addnewsvideo("idtintuc")
            End If
        End Sub
        Private Function addnewsGuiluon() As Boolean
            Dim ctlNews As New NV_NewsController
            Try
                If Request.Item("tin") <> "" Then
                    Dim tin As String
                    tin = Request.Item("tin")
                    'update news
                    Dim stitle As String
                    Dim ssummary As String
                    Dim scontent As String
                    Dim spicture As String
                    Dim spictureHOT As String
                    Dim iCategory As Integer
                    Dim iHotsite As Integer
                    Dim iNotes As Integer
                    Dim iHotCat As Integer
                    Dim sExSummary As String
                    Dim sConTentImg As String
                    Dim iBL As Integer
                    Dim inguon As Integer
                    ' Insert
                    stitle = Me.txtTitle.Text
                    ssummary = Me.txtSummary.Text
                    sExSummary = TextEditor2.Text
                    scontent = TextEditor1.Text
                    sConTentImg = txtLinkNguon.Text
                    If txtLinkImage.Text <> "" Then
                        spicture = txtLinkImage.Text
                    Else
                        If Me.imgNews.ImageUrl <> "" Then
                            spicture = Path.GetDirectoryName(imgNews.ImageUrl) & "/" & Path.GetFileName(imgNews.ImageUrl)
                            spicture = spicture.Replace("\Portals\0\News\", "")
                            spicture = spicture.Replace("\", "/")
                        Else
                            spicture = ""
                        End If
                    End If

                    If txtLinkImageHOT.Text <> "" Then
                        spictureHOT = txtLinkImageHOT.Text
                    Else
                        If Me.imgNewsHOT.ImageUrl <> "" Then
                            spictureHOT = Path.GetDirectoryName(imgNewsHOT.ImageUrl) & "/" & Path.GetFileName(imgNewsHOT.ImageUrl)
                            spictureHOT = spictureHOT.Replace("\Portals\0\News\HOT\", "")
                            spictureHOT = spictureHOT.Replace("\", "/")
                        Else
                            spictureHOT = ""
                        End If
                    End If
                    iCategory = CInt(Me.ddlCategory.SelectedItem.Value)
                    iHotCat = CInt(IIf(Me.chkHotCat.Checked(), 1, 0))
                    iHotsite = CInt(IIf(Me.chkHotSite.Checked(), 1, 0))
                    iNotes = CInt(IIf(Me.chkNotes.Checked(), 1, 0))
                    iBL = CInt(IIf(Me.chkBL.Checked(), 1, 0))
                    inguon = CInt(Me.ddlNguonTin.SelectedItem.Value)
                    'DataProvider.Instance.NV_News_update_XB(tin, iCategory, stitle, spicture, ssummary, scontent, 1, iHotCat, iHotsite, iNotes, PortalId, 2, sExSummary, sConTentImg, spictureHOT, iBL, inguon)
                    ctlNews.Update_XB(tin, iCategory, stitle, spicture, ssummary, scontent, 1, iHotCat, iHotsite, iNotes, PortalId, 2, sExSummary, sConTentImg, spictureHOT, iBL, inguon)
                    Response.Redirect(NavigateURL(), True)
                Else
                    Dim stitle As String
                    Dim ssummary As String
                    Dim scontent As String
                    Dim spicture As String
                    Dim spictureHOT As String
                    Dim iCategory As Integer
                    Dim iHotsite As Integer
                    Dim iNotes As Integer
                    Dim iHotCat As Integer
                    Dim sExSummary As String
                    Dim sConTentImg As String
                    Dim iBL As Integer
                    Dim inguon As Integer
                    ' Insert
                    stitle = Me.txtTitle.Text
                    ssummary = Me.txtSummary.Text
                    sExSummary = TextEditor2.Text
                    scontent = TextEditor1.Text
                    sConTentImg = txtLinkNguon.Text

                    If txtLinkImage.Text <> "" Then
                        spicture = txtLinkImage.Text
                    Else
                        If Me.imgNews.ImageUrl <> "" Then
                            spicture = Path.GetDirectoryName(imgNews.ImageUrl) & "/" & Path.GetFileName(imgNews.ImageUrl)
                            spicture = spicture.Replace("\Portals\0\News\", "")
                            spicture = spicture.Replace("\", "/")
                        Else
                            spicture = ""
                        End If
                    End If

                    If txtLinkImageHOT.Text <> "" Then
                        spictureHOT = txtLinkImageHOT.Text
                    Else
                        If Me.imgNewsHOT.ImageUrl <> "" Then
                            spictureHOT = Path.GetDirectoryName(imgNewsHOT.ImageUrl) & "/" & Path.GetFileName(imgNewsHOT.ImageUrl)
                            spictureHOT = spictureHOT.Replace("\Portals\0\News\HOT\", "")
                            spictureHOT = spictureHOT.Replace("\", "/")
                        Else
                            spictureHOT = ""
                        End If
                    End If

                    iCategory = CInt(Me.ddlCategory.SelectedItem.Value)
                    iHotCat = CInt(IIf(Me.chkHotCat.Checked(), 1, 0))
                    iHotsite = CInt(IIf(Me.chkHotSite.Checked(), 1, 0))
                    iNotes = CInt(IIf(Me.chkNotes.Checked(), 1, 0))
                    iBL = CInt(IIf(Me.chkBL.Checked(), 1, 0))
                    inguon = CInt(Me.ddlNguonTin.SelectedItem.Value)
                    'isactive = CInt(IIf(Me.chkHotSite.Checked(), 1, 0))
                    ctlNews.Insert_XB(iCategory, stitle, spicture, ssummary, scontent, 1, iHotCat, iHotsite, iNotes, PortalId, UserId, 2, sExSummary, sConTentImg, spictureHOT, iBL, inguon)
                    Me.lbResult.Text = "Cập nhật tin thành công"
                    Response.Redirect(NavigateURL(), True)
                End If
                Return True
            Catch ex As Exception
                Me.lbResult.Text = "Lỗi cập nhật tin"
                ProcessModuleLoadException(Me, ex)
                Return False
            End Try
        End Function
        Private Sub lbtGuiluon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtGuiluon.Click
            If addnewsGuiluon() Then
                clearcontroldata()
                ' addnewsvideo("idtintuc")
            End If
        End Sub
        Private Sub lbtCancelTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtCancelTop.Click
            Try
                If Request.Item("tin") <> "" Then
                    'Dim tin As Integer
                    'tin = CInt(Request.Item("tin"))
                    Response.Redirect(NavigateURL(), True)
                Else
                    clearcontroldata()
                End If
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
        Private Sub clearcontroldata()
            Me.txtSummary.Text = ""
            Me.txtTitle.Text = ""
            TextEditor1.Text = "Đang cập nhật"
            TextEditor2.Text = "Đang cập nhật"
            Me.imgNewsHOT.ImageUrl = ""
            Me.imgNews.ImageUrl = ""
        End Sub
#End Region

        Private Sub lbtUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtUpload.Click
            Try
                If Page.IsPostBack Then
                    Dim PathtoWrite As String = Request.MapPath(PortalSettings.HomeDirectory) & "News/"
                    Dim dateToUse As DateTime = DateTime.Now
                    Dim fullpath As String = String.Concat(PathtoWrite, "\", dateToUse.Year, "\", dateToUse.Month, "\", dateToUse.ToString("dd"), "\")
                    Dim shortpath As String = String.Concat(PortalSettings.HomeDirectory, "News/", dateToUse.Year, "/", dateToUse.Month, "/", dateToUse.ToString("dd"), "/")
                    If Not System.IO.Directory.Exists(fullpath) Then
                        System.IO.Directory.CreateDirectory(fullpath)
                    End If
                    Dim strFileName As String
                    Dim strFileNamePath As String
                    Dim strExtension As String = ""
                    Dim strMessage As String = ""
                    Dim strChangeName As String
                    If Me.txtFile.PostedFile.FileName <> "" Then
                        strFileName = System.IO.Path.GetFileName(Me.txtFile.PostedFile.FileName)
                        strExtension = Path.GetExtension(strFileName)
                        strFileNamePath = System.IO.Path.GetFullPath(Me.txtFile.PostedFile.FileName)
                        strChangeName = strFileName.Replace(strFileName, GetUserName(UserId) & "_" & DateTime.Now.Ticks & ".jpg")
                        'Me.txtFile.PostedFile.SaveAs(Request.MapPath(PortalSettings.HomeDirectory) & "News/" & strChangeName)
                        Me.txtFile.PostedFile.SaveAs(fullpath & strChangeName)
                        Me.imgNews.ImageUrl = shortpath & strChangeName
                        Me.imgNews.Visible = True
                        Me.lblMessage.Text = Request.Url.Host & shortpath & strChangeName
                    End If
                End If

            Catch exc As Exception 'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try

        End Sub
        Private Sub lbtUploadHOT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtUploadHOT.Click
            Try
                If Page.IsPostBack Then
                    Dim PathtoWrite As String = Request.MapPath(PortalSettings.HomeDirectory) & "News/HOT/"
                    Dim dateToUse As DateTime = DateTime.Now
                    Dim fullpath As String = String.Concat(PathtoWrite, "\", dateToUse.Year, "\", dateToUse.Month, "\", dateToUse.ToString("dd"), "\")
                    Dim shortpath As String = String.Concat(PortalSettings.HomeDirectory, "News/HOT/", dateToUse.Year, "/", dateToUse.Month, "/", dateToUse.ToString("dd"), "/")
                    If Not System.IO.Directory.Exists(fullpath) Then
                        System.IO.Directory.CreateDirectory(fullpath)
                    End If
                    Dim strFileName As String
                    Dim strFileNamePath As String
                    Dim strExtension As String = ""
                    Dim strMessage As String = ""
                    Dim strChangeName As String

                    If Me.txtFileHOT.PostedFile.FileName <> "" Then
                        strFileName = System.IO.Path.GetFileName(Me.txtFileHOT.PostedFile.FileName)
                        strExtension = Path.GetExtension(strFileName)
                        strFileNamePath = System.IO.Path.GetFullPath(Me.txtFileHOT.PostedFile.FileName)
                        strChangeName = strFileName.Replace(strFileName, GetUserName(UserId) & "_" & DateTime.Now.Ticks & ".jpg")
                        Me.txtFileHOT.PostedFile.SaveAs(fullpath & strChangeName)
                        Me.imgNewsHOT.ImageUrl = shortpath & strChangeName
                        Me.imgNewsHOT.Visible = True
                        Me.lblMessageHOT.Text = Request.Url.Host & shortpath & strChangeName

                        'uploadFileUsingFTP("ftp://localhost/" & linklocal, "linklocal")

                    End If

                End If

            Catch exc As Exception 'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try

        End Sub
        Private Sub lbtDeleteTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtDeleteTop.Click
            Try
                If Request.Item("tin") <> "" Then
                    Dim tin As Integer
                    tin = CInt(Request.Item("tin"))
                    DataProvider.Instance.NV_News_Delete(tin, 1)
                    Response.Redirect(NavigateURL(), True)
                Else
                    clearcontroldata()
                End If
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
        Private Sub lbtDeleteBottom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtDeleteBottom.Click
            Try
                If Request.Item("tin") <> "" Then
                    Dim tin As Integer
                    tin = CInt(Request.Item("tin"))
                    DataProvider.Instance.NV_News_Delete(tin, 1)
                    Response.Redirect(NavigateURL(), True)
                Else
                    clearcontroldata()
                End If
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
        Private Sub BindddlCategories()
            Dim ctlNewsCategories As New NV_NewsCategoriesController
            Dim arrNewsCategories As New ArrayList
            arrNewsCategories = ctlNewsCategories.GetAll(PortalId)
            Dim arrTemp As New ArrayList
            Dim objNewsCategories As NV_NewsCategoriesInfo
            Dim objNewsCategoriesTemp As NV_NewsCategoriesInfo

            If arrNewsCategories.Count > 0 Then
                For Each objNewsCategories In arrNewsCategories
                    If objNewsCategories.ParentId = 0 Then
                        arrTemp.Add(objNewsCategories)
                        For Each objNewsCategoriesTemp In arrNewsCategories
                            If objNewsCategoriesTemp.ParentId = objNewsCategories.CategoryID Then
                                objNewsCategoriesTemp.CategoryName = "||---->" & objNewsCategoriesTemp.CategoryName
                                arrTemp.Add(objNewsCategoriesTemp)
                            End If
                        Next
                    End If
                Next
            End If

            Me.ddlCategory.DataSource = arrTemp
            Me.ddlCategory.DataTextField = "CategoryName"
            Me.ddlCategory.DataValueField = "CategoryId"
            Me.ddlCategory.DataBind()
        End Sub
        Public Function GetUserName(ByVal userid As Integer) As String
            If userid = -1 Then
                GetUserName = "Bạn đọc Gửi"
            Else
                Return UserController.GetUser(PortalId, userid, True).Username
            End If
        End Function
        'Nguon Tin
        Private Sub BindNguonTin()
            Dim ctlNewRelated As New NV_NewsNguonController
            Me.ddlNguonTin.DataSource = ctlNewRelated.GetAll()
            Me.ddlNguonTin.DataValueField = "id"
            Me.ddlNguonTin.DataTextField = "Title"
            Me.ddlNguonTin.DataBind()
        End Sub
        'TinLienQuan
        Private Sub binddrgDataViewerR()
            Try
                Dim ctlNews As New NV_NewsController
                Dim arrNews As New ArrayList
                arrNews = ctlNews.SelectTopNewsByCat_Admin(Me.ddlCategoryR.SelectedValue)
                Me.drgDataViewerR.DataSource = arrNews
                Me.drgDataViewerR.DataBind()
            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub
        Protected Sub drgDataViewerR_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles drgDataViewerR.ItemDataBound
            If e.Item.ItemType = ListItemType.Header Then
                Dim chkUserAll As CheckBox
                'If Not dgrProducts. Is Nothing Then
                chkUserAll = CType(e.Item.FindControl("chkItemsTop"), CheckBox)
                If Not chkUserAll Is Nothing Then
                    chkUserAll.Attributes.Add("OnClick", "javascript:IsCheckBoxSelected(" & drgDataViewerR.ClientID & "," & chkUserAll.ClientID & ")")
                End If
                'End If
            End If
        End Sub
        Private Sub BindNewsRelated()
            Dim ctlNewRelated As New NV_NewsRelated_Controller
            Me.dlNewsRelated.DataSource = ctlNewRelated.News_Related_GetAll(Request.Item("tin"))
            Me.dlNewsRelated.DataBind()
        End Sub

        Private Sub InitializeComponent()
        End Sub
        Protected Overrides Sub OnInit(ByVal e As EventArgs)
            InitializeComponent()
            MyBase.OnInit(e)
        End Sub
        Protected Sub drgDataViewerR_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles drgDataViewerR.PageIndexChanged
            Me.drgDataViewerR.CurrentPageIndex = e.NewPageIndex
            binddrgDataViewerR()
        End Sub
        Protected Sub ddlCategoryR_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim idCountry As String = ddlCategoryR.SelectedValue.ToString()
            If idCountry.Equals("") Then
                binddrgDataViewerR()
            Else
                binddrgDataViewerR()
            End If
        End Sub
        Private Sub BindddlCategories2()
            Dim ctlNewsCategories As New NV_NewsCategoriesController
            Dim arrNewsCategories As New ArrayList
            arrNewsCategories = ctlNewsCategories.GetAll(PortalId)
            Dim arrTemp As New ArrayList
            Dim objNewsCategories As NV_NewsCategoriesInfo
            Dim objNewsCategoriesTemp As NV_NewsCategoriesInfo

            If arrNewsCategories.Count > 0 Then
                For Each objNewsCategories In arrNewsCategories
                    If objNewsCategories.ParentId = 0 Then
                        arrTemp.Add(objNewsCategories)
                        For Each objNewsCategoriesTemp In arrNewsCategories
                            If objNewsCategoriesTemp.ParentId = objNewsCategories.CategoryID Then
                                objNewsCategoriesTemp.CategoryName = "||----" & objNewsCategoriesTemp.CategoryName
                                arrTemp.Add(objNewsCategoriesTemp)
                            End If
                        Next
                    End If
                Next
            End If

            Me.ddlCategoryR.DataSource = arrTemp
            Me.ddlCategoryR.DataTextField = "CategoryName"
            Me.ddlCategoryR.DataValueField = "CategoryId"
            Me.ddlCategoryR.DataBind()
            Me.ddlCategoryR.Items.Insert(0, New ListItem("--Tất cả thư mục--", 0))

        End Sub
        Protected Sub lbtSendForApprove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtSendForApprove.Click
            Dim i As Integer
            Dim chkBox As CheckBox
            Dim ctlNews As New NV_NewsRelated_Controller

            For i = 0 To (Me.drgDataViewerR.Items.Count - 1)
                Try
                    chkBox = CType(Me.drgDataViewerR.Items(i).FindControl("chkItems"), CheckBox)
                    If Not chkBox Is Nothing Then
                        If chkBox.Checked = True Then
                            ' Add product to display product detail
                            ctlNews.News_Related_Add(Request("tin"), drgDataViewerR.DataKeys(i).ToString())
                        End If
                    End If
                Catch ex As Exception
                    ProcessModuleLoadException(Me, ex)
                End Try
            Next
            binddrgDataViewerR()
            BindNewsRelated()
        End Sub
        Public Function GetTitle(ByVal newid As String) As String
            Dim ctlCauthu As New NV_NewsController
            Dim objCauthu As NV_NewsInfo
            objCauthu = ctlCauthu.GetByID(newid)
            Return objCauthu.Title
        End Function
        Public Sub DelNewsRelated(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim lnk As LinkButton = CType(sender, LinkButton)
            Dim id As Integer = lnk.CommandArgument
            Dim cltImg As New NV_NewsRelated_Controller
            cltImg.News_Related_Del(id)
            BindNewsRelated()
        End Sub

    End Class

End Namespace
